<template>
  <!--
      	作者：sfh
      	时间：2023-07-01
      	描述：插件中心-限时拼团-活动列表
      -->
  <div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form
        size="small"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="">
          <el-input
            v-model="formInline.merch_name"
            placeholder="请输入商户名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-input
            v-model="formInline.store_name"
            placeholder="请输入门店名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-input
            v-model="formInline.product_name"
            placeholder="请输入商品名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="起始时间">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker
              size="small"
              v-model="formInline.create_time"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
          <el-button type="primary" @click="onExport">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="product-content">
      <el-form ref="form" :model="form" label-width="100px">
        <div class="table-wrap">
          <el-table
            size="small"
            :data="tableData"
            border
            style="width: 100%;"
            v-loading="loading"
          >
            <el-table-column prop="assemble_bill_no" label="单号" width="150"></el-table-column>
            <el-table-column prop="merch.name" label="供货商家" width="150"></el-table-column>
            <el-table-column
              prop="store.store_name"
              label="自提门店"
              width="100"
            ></el-table-column>
            <el-table-column
              label="拼团商品"
              width="250"
            >
              <template slot-scope="scope">
                <span v-if="scope.row.assembleSku.product_attr" class="fbb">{{ scope.row.assembleProduct.product_name }}（{{ scope.row.assembleSku.product_attr }}）</span>
                <span v-else class="fbb">{{ scope.row.assembleProduct.product_name }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="actual_people"
              label="已拼人数"
              width="150"
            ></el-table-column>
            <el-table-column
              prop="total_people"
              label="开团人数"
              width="120"
            ></el-table-column>
            <el-table-column
              prop="actual_num"
              label="已购数量"
              width="120"
            ></el-table-column>            
            <el-table-column
              prop="total_num"
              label="总共数量"
              width="120"
            ></el-table-column>
            <el-table-column
              prop="actual_amount"
              label="实收金额"
              width="120"
            ></el-table-column>            
            <el-table-column
              prop="total_amount"
              label="应收金额"
              width="120"
            ></el-table-column>
            <el-table-column
              prop="refund_num"
              label="退款数"
              width="120"
            ></el-table-column>            
            <el-table-column
              prop="refund_amount"
              label="退款金额"
              width="120"
            ></el-table-column>
            <el-table-column
              prop="store_kpi_amount"
              label="平台金额"
              width="120"
            ></el-table-column>
            <el-table-column
              prop="supply_actual_amount"
              label="供货商金额"
              width="120"
            ></el-table-column>
            <el-table-column
              prop="store_amount"
              label="站点金额"
              width="120"
            ></el-table-column>
            <el-table-column
              prop="delivery_status"
              label="配送状态"
              width="120"
            ></el-table-column>
            <el-table-column
              prop="status_text"
              label="拼团状态"
              width="120"
            ></el-table-column>
            <el-table-column
              prop="create_time"
              label="创建时间"
              width="150"
            ></el-table-column>
            <el-table-column fixed="right" label="操作" width="90px">
              <template slot-scope="scope">
                <div>
                <el-button
                  @click="viewClick(scope.row)"
                  type="text"
                  size="small"
                  >详情</el-button
                >
                <el-button
                  @click="listProduct(scope.row)"
                  type="text"
                  size="small"
                  >订单</el-button
                >
                <el-button
                  @click="deleteClick(scope.row)"
                  type="text"
                  size="small"
                  wi
                  >删除</el-button
                >
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        >
        </el-pagination>
      </div>
    </div>
    <!-- 拼团商品列表 -->
    <el-dialog title="拼团商品" :visible.sync="prodVisible" @close="prodVisible=false" :close-on-click-modal="true" :close-on-press-escape="false" width="1300px">
      <div class="dialog-height">
        <Orderlist :assemble_bill_id="assemble_bill_id"></Orderlist>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import AssembleApi from "@/api/assemble.js";
import Product from "@/components/product/Product.vue";
import Orderlist from "./orderlist.vue";
import qs from 'qs';
export default {
  components: { Product, Orderlist},
  data() {
    return {
      prodVisible: false,
      /*是否打开选择商品*/
      isproduct: false,
      /*产品去重*/
      excludeIds: [],
      /*是否打开规格选择*/
      isspecs: false,
      /*查询规格当前商品*/
      curProduct: {},
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      form: {},
      /*是否打开添加弹窗*/
      open_add: false,
      /*是否打开编辑弹窗*/
      open_edit: false,
      /*当前编辑的对象*/
      userModel: {},
      formInline: {
        merch_name:'',
        store_name:'',
        create_time:'',
        product_name:'',
        
      },
      status: ["未开始", "进行中", "已结束"],
      file: {},
      activity_id: null,
      assemble_bill_id: null
    };
  },
  created() {
    /*获取列表*/
    this.getTableList();
  },
  methods: {
    /*选择第几页*/
    handleCurrentChange(val) {
      this.curPage = val;
      this.getTableList();
    },
    
    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getTableList();
    },

    /*获取列表*/
    getTableList() {
      let self = this;
      let Params = self.formInline;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      self.loading = true;
      AssembleApi.listBill(Params, true)
        .then((data) => {
          self.loading = false;
          self.tableData = data.data.list.data;
          self.totalDataNumber = data.data.list.total;
        })
        .catch((error) => {
          self.loading = false;
        });
    },
    /* 审核*/
    toAudit(id) {
      this.$router.push({
        path: "/plus/assemble/index",
        query: {
          type: "audit",
          id: id,
        },
      });
    },
    /*搜索查询*/
    onSubmit() {
      this.curPage = 1;
      this.getTableList();
    },
    handleClose() {
      this.prodVisible = false;
    },
    /*打开添加*/
    addClick() {
      this.$router.push("/plus/assemble/active/add");
    },

    /*打开详情*/
    viewClick(row) {
      let assemble_bill_id = row.assemble_bill_id;
      this.$router.push({
        path: "/plus/assemble/bill/detail",
        query: {
          assemble_bill_id: assemble_bill_id,
        },
      });
    },

    prdClick(row) {
      let assemble_activity_id = row.assemble_activity_id;
      this.$router.push({
        path: "/plus/assemble/active/product",
        query: {
          assemble_activity_id: assemble_activity_id,
        },
      });
    },
    //选择商品
    chooseProduct(row) {
      let assemble_activity_id = row.assemble_activity_id;
      this.activity_id = assemble_activity_id;
      let arr = [];
      let list = [];
      list.forEach((item) => {
        arr.push(item.product_id);
      });
      this.excludeIds = arr;
      this.isproduct = true;
    },
    //选择商品
    listProduct(e) {
      this.assemble_bill_id = e.assemble_bill_id;
      this.prodVisible = true;
    },
    /*关闭弹窗*/
    closeDialogFunc(e) {
      let self = this;
      self.isproduct = false;
      if (e.type == "success") {
        let product = e.params;
        console.log(product);
        let product_id = product.product_id;
        this.$router.push({
            path: "/plus/assemble/active/addprd",
            query: {
                activity_id:this.activity_id,
                product_id: product_id
            },
        });
      }
    },
    /*删除*/
    deleteClick(row) {
      let self = this;
      self
        .$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
        .then(() => {
          AssembleApi.delActive(
            {
              assemble_activity_id: row.assemble_activity_id,
            },
            true
          )
            .then((data) => {
              if (data.code == 1) {
                self.$message({
                  message: "活动删除成功",
                  type: "success",
                });
                //刷新页面
                self.getTableList();
              } else {
                self.$message.error("系统发生错误");
              }
            })
            .catch((error) => {});
        })
        .catch(() => {});
    },
    onExport: function() {
      let baseUrl = window.location.protocol + '//' + window.location.host;
      window.location.href = baseUrl + '/index.php/mall/plus.assemble.bill/export?' + qs.stringify(this.formInline);
    }
  },
};
</script>

<style>
.fbb {
  border-bottom: 1px solid #409eff;
  color: #409eff;
  padding-bottom: 0px;
  width: 7px;
}
.dialog-height {
  height: 70vh;
}
.user{
  padding-bottom: 100px;
}
</style>
